{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "00fa35fe",
   "metadata": {},
   "source": [
    "-------\n",
    "* 2022/10/10 / week07\n",
    "* Python学习记录\n",
    "* 记录人：zhichao\n",
    "-------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "47e6f461",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "\n",
    "* 1. 有序的数据结构——字符串(str)\n",
    "\n",
    "* 2. 有序的数据结构——列表(list)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "464197f8",
   "metadata": {},
   "source": [
    "## 1. 字符串（string）\n",
    "\n",
    "> 1. 关于字符串的基本内容\n",
    "> 2. 关于字符串的方法及函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3c7d80a2",
   "metadata": {},
   "source": [
    "### 1.1 [关于字符串的基本内容](https://docs.python.org/3/tutorial/introduction.html#strings)\n",
    "\n",
    "* Single quotes: 'allows embedded \"double\" quotes'\n",
    "\n",
    "* Double quotes: \"allows embedded 'single' quotes\"\n",
    "\n",
    "* Triple quoted: '''Three single quotes''', \"\"\"Three double quotes\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ecc8a8d2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'spam eggs'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'spam eggs' "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "0cfa1ca6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(type('spam eggs' ))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "73229dba",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(type(\"spam eggs\" ))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b351c7e0",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-5-f70cf6904edb>, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-5-f70cf6904edb>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    'doesn't'\u001b[0m\n\u001b[1;37m           ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "'doesn't'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ae77b012",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 以上解决方案\n",
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a17dc3f5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'doesn\\'t'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "39132421",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 三引号：保留字符串信息的 格式信息,保留完整的数据信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "687aa256",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''doesn't'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "a3cf4dea",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "EOL while scanning string literal (<ipython-input-11-b52479b251c1>, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-11-b52479b251c1>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    \"Triple quoted strings may span multiple lines - all associated whitespace will be included in the string literal.\u001b[0m\n\u001b[1;37m                                                                                                                      ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m EOL while scanning string literal\n"
     ]
    }
   ],
   "source": [
    "\"Triple quoted strings may span multiple lines - all associated whitespace will be included in the string literal.\n",
    "\n",
    "String literals that are part of a single expression and have only whitespace between them will be implicitly converted to a single string literal. That is\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "e00f243e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Triple quoted strings may span multiple lines - all associated whitespace will be included in the string literal.\n",
      "\n",
      "String literals that are part of a single expression and have only whitespace between them will be implicitly converted to a single string literal. That is\n"
     ]
    }
   ],
   "source": [
    "print('''Triple quoted strings may span multiple lines - all associated whitespace will be included in the string literal.\n",
    "\n",
    "String literals that are part of a single expression and have only whitespace between them will be implicitly converted to a single string literal. That is''')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "6c893bb2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Usage: thingy [OPTIONS]\n",
      "     -h                        Display this usage message\n",
      "     -H hostname               Hostname to connect to\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(\"\"\"\\\n",
    "Usage: thingy [OPTIONS]\n",
    "     -h                        Display this usage message\n",
    "     -H hostname               Hostname to connect to\n",
    "\"\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "fa312051",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<script type=\"importmap\" nonce=\"\"> { \"imports\": {\"rms-answers-HomepageVNext-PeregrineWidgets\":\"https://assets.msn.com/bundles/v1/bingHomepage/latest/widget-initializer.js\"} } </script>\n"
     ]
    }
   ],
   "source": [
    "print('''<script type=\"importmap\" nonce=\"\"> { \"imports\": {\"rms-answers-HomepageVNext-PeregrineWidgets\":\"https://assets.msn.com/bundles/v1/bingHomepage/latest/widget-initializer.js\"} } </script>''')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ccc4dbd4",
   "metadata": {},
   "source": [
    "### 1.2 [关于字符串的方法及函数](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str)\n",
    "\n",
    "> 1. 字符串是可以拼接的（字符串的运算）,用 + 进行字符串之间的拼接\n",
    "> 2. 字符串是有顺序的,从第一个字符开始，从0依次往后；有长度，可以用len()检查字符串的长度\n",
    "> 3. 字符串的取值：\n",
    ">> 1. 取单个值 :从左往右（正数，第一个值是0），从右往左（负数，第一个值是-1）\n",
    ">> 2. 取多个值 :切片的方法，两个值作为 取值的区间"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "0ab7b3f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "new_name = [\"小明\",\"小红\",\"张杰\",\"李华\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "6b60d8c2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方学院团委欢迎小明\n",
      "广州南方学院团委欢迎小红\n",
      "广州南方学院团委欢迎张杰\n",
      "广州南方学院团委欢迎李华\n"
     ]
    }
   ],
   "source": [
    "for i in new_name:\n",
    "    print(\"广州南方学院团委欢迎\"+i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "ffd6b77b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院团委欢迎小明'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"广州南方学院团委欢迎\"+\"小明\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "f5fe9188",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院团委欢迎小明'"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text = '广州南方学院团委欢迎小明'\n",
    "text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "a84efcd0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "87cdd63d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "0766b069",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'南'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "77def850",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "string index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-30-a4cec855b1ea>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mtext\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m12\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m: string index out of range"
     ]
    }
   ],
   "source": [
    "text[12]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "b99f5135",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "e78ab13f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'团委'"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[6]+text[7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "11bce56d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'团委'"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用 切片 的方法进行多个值取值\n",
    "text[6:8]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a110fed3",
   "metadata": {},
   "source": [
    "## 2. 有序的数据结构——列表(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0235eecf",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
